package com.exp.bookhouse.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exp.bookhouse.pojo.Order;
import com.exp.bookhouse.pojo.vo.TableVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface OrderMapper extends BaseMapper<Order> {

    IPage<Order> getAllOrder(IPage<Order> page, @Param("order_status") Integer payStatus, @Param("openid") String openid);

    Order queryOrderById(Long id);

    @Select("select amount from tb_order")
    List<Long> queryOrderTotalPrice();

    List<TableVo> queryOrderByMonth();

    @Select("select sum(amount) as total \n" +
            "from tb_order \n" +
            "where DATE_FORMAT( create_time, '%Y%m' ) = DATE_FORMAT( CURDATE( ) , '%Y%m' )\n")
    Long queryOrderTotalPriceByMonth();

    List<TableVo> queryOrderByDay();

    @Select("select sum(amount) as total \n" +
            "from tb_order \n" +
            "where to_days(create_time) = to_days(now())")
    Long queryOrderTotalPriceByDay();


    List<TableVo> queryOrderByYear();

    @Select("select sum(amount) as total \n" +
            "from tb_order \n" +
            "where YEAR(create_time)=YEAR(NOW())")
    Long queryOrderTotalPriceByYear();

}
